package com.cxyzy.demo

import android.content.Context
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView

class NotesAdapter(private val context: Context, private val data: MutableList<Note>) :
    RecyclerView.Adapter<NotesAdapter.SimpleViewHolder>() {

    var onItemClickListener: OnItemClickListener? = null

    override fun onBindViewHolder(holder: SimpleViewHolder, position: Int) {
        holder.textView?.text = data[position].text
        holder.commentTextView?.text = data[position].comment
        holder.itemView.setOnClickListener { onItemClickListener?.OnItemClick(position) }
    }

    override fun getItemCount(): Int = data.size

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SimpleViewHolder {
        val view = LayoutInflater.from(context).inflate(R.layout.item_note, parent, false)
        return SimpleViewHolder(view)
    }

    inner class SimpleViewHolder(view: View) : RecyclerView.ViewHolder(view) {
        var textView: TextView = view.findViewById(R.id.textViewNoteText)
        var commentTextView: TextView = view.findViewById(R.id.textViewNoteComment)
    }

}